export const { list: navTypeList, map: navTypeMap } = createDict([
    {
        label: '内部模块',
        value: 0
    },
    {
        label: '内嵌外链',
        value: 1
    },
    {
        label: '跳转外链',
        value: 2
    },
    {
        label: '大屏',
        value: 3
    }
])

export const { list: menuTypeList, map: menuTypeMap } = createDict([
    {
        label: '目录',
        value: 0
    },
    {
        label: '菜单',
        value: 1
    },
    {
        label: '按钮',
        value: 2
    }
])

export const { list: sexTypeList, map: sexTypeMap } = createDict([
    {
        label: '男',
        value: '0'
    },
    {
        label: '女',
        value: '1'
    }
])

export function createDict (
    list = [],
    {
        listLabelField = 'label',
        listValueField = 'value',
        dictLabelField = 'label',
        dictValueField = 'value'
    } = {}
) {
    const _list = list.map(item => {
        return {
            ...item,
            [dictLabelField]: item[listLabelField],
            [dictValueField]: item[listValueField]
        }
    })

    const map = _list.reduce((prev, current) => {
        prev[current[dictValueField]] = current
        return prev
    }, {})

    return {
        list: _list,
        map
    }
}